package com.stock.controller;

import com.stock.domain.vo.request.UserAddReqVo;
import com.stock.domain.vo.request.UserEditReqVO;
import com.stock.domain.vo.request.UserOwnRoleReqVo;
import com.stock.domain.vo.request.UserPageReqVo;
import com.stock.domain.vo.response.PageResponse;
import com.stock.domain.vo.response.Response;
import com.stock.domain.vo.response.UserInfoRespVo;
import com.stock.domain.vo.response.UserOwnRoleRespVo;
import com.stock.service.UserServiceExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class UserControllerExt {
    @Autowired
    private UserServiceExt userService;

//    @PostMapping("/login")
//    public Response<LoginRespVoExt> login(@RequestBody LoginRequest vo) {
//        return userService.login(vo);
//    }

    /**
     * 多条件综合查询用户分页信息，条件包含：分页信息 用户创建日期范围
     * @param userPageReqVo
     * @return
     */
    @PostMapping("/users")
    public Response<PageResponse> pageUsers(@RequestBody UserPageReqVo userPageReqVo){
        return this.userService.pageUsers(userPageReqVo);
    }

    /**
     * 添加用户信息
     * @param vo
     * @return
     */
    @PostMapping("/user")
    public Response<String> addUser(@RequestBody UserAddReqVo vo){
        return this.userService.addUser(vo);
    }

    /**
     * 更新用户信息
     * @param vo
     * @return
     */
    @PutMapping("/user")
    public Response<String> updateUser(@RequestBody UserEditReqVO vo){
        return this.userService.updateUser(vo);
    }

    /**
     * 获取用户具有的角色信息，以及所有角色信息
     * @param userId
     * @return
     */
    @GetMapping("/user/roles/{userId}")
    public Response<UserOwnRoleRespVo> getUserOwnRole(@PathVariable("userId")Long userId){
        return this.userService.getUserOwnRole(userId);
    }

    /**
     * 更新用户角色信息
     * @param vo
     * @return
     */
    @PutMapping("/user/roles")
    public Response<String> updateUserOwnRoles(@RequestBody UserOwnRoleReqVo vo){
        return this.userService.updateUserOwnRoles(vo);
    }

    /**
     * 批量删除用户信息
     * delete请求可通过请求体携带数据
     * @param userIds
     * @return
     */
    @DeleteMapping("/user")
    public Response<String> deleteUsers(@RequestBody List<Long> userIds){
        return this.userService.deleteUsers(userIds);
    }


    /**
     * 根据用户id查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/user/info/{userId}")
    public Response<UserInfoRespVo> getUserInfo(@PathVariable("userId") Long id){
        return userService.getUserInfo(id);
    }
}
